# randpass.py
import random
# 导入所有的英文字符和数字字符
from string import ascii_letters, digits
# print(ascii_letters, digits)
def randpass(n=8):
    # 准备空字符串，用于拼接
    string = ''
    # 随机范围
    all_chars = ascii_letters + digits
    # 随机获取8个，需要循环8次
    for i in range(n):
        # print(random.choice(all_chars))
        # 将每次获取的随机拼接起来
        # string = string + random.choice(all_chars)
        string += random.choice(all_chars)
    return string
if __name__ == '__main__':
    print(randpass(10))
    print(randpass())
    print(randpass(12))


